package com.liyong.bos.controller;

import com.liyong.bos.domain.BcRegion;
import com.liyong.bos.service.BcRegionService;
import com.liyong.bos.utils.POIUtil;
import com.liyong.bos.utils.TableJsonData;
import com.liyong.bos.vo.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by ApacheMoy on 2017/4/9.
 */

@Controller
@RequestMapping(value = "/bcRegion")
public class BcRegionController {
    @Autowired
    private BcRegionService bcRegionService;

    /**
     *
     * @param myFile
     * @return
     */
    @RequestMapping(value = "/uploadBcRegion",method = RequestMethod.POST)
    public @ResponseBody String upLoadRegionData(MultipartFile myFile){
        try {
            List<String[]> list=POIUtil.readExcel(myFile);
            bcRegionService.bcRegionPush(list);
        } catch (IOException e) {
            return "error";
        }
        return  "success";
    }
    @RequestMapping(value = "/getBcRegion")
    public @ResponseBody
    TableJsonData getBcRegion(PageInfo pageInfo, HttpServletRequest request, HttpServletResponse response){
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Cache-Control", "no-store");
        response.setHeader("Pragma", "no-cache");
        TableJsonData tableJsonData=new TableJsonData();
        List<BcRegion> bcRegions=bcRegionService.bcRegionGet(pageInfo.getPage(),pageInfo.getRows());
        int countPage=bcRegionService.countByPage();
        tableJsonData.setTotal(countPage);
        tableJsonData.setRows(bcRegions);
        return  tableJsonData;
    }
}
